<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "record".
 *
 * @property integer $audio_id
 * @property integer $user_id
 * @property boolean $prase
 * @property integer $listen_times
 * @property string $listen_time
 * @property boolean $collect
 * @property integer $read_times
 * @property double $weight
 * @property string $ctime
 *
 * @property Audio $audio
 * @property User $user
 */
class Record extends \yii\db\ActiveRecord {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'record';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['audio_id', 'user_id',], 'required'],
            [['audio_id', 'user_id', 'listen_times', 'read_times'], 'integer'],
            [['prase', 'collect',], 'boolean'],
            [['weight'], 'number'],
            [['listen_time', 'ctime'], 'safe'],
            [['audio_id'], 'exist', 'skipOnError' => true, 'targetClass' => Audio::className(), 'targetAttribute' => ['audio_id' => 'id']],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'audio_id' => 'Audio ID',
            'user_id' => 'User ID',
            'listen_times' => 'Listen Times',
            'listen_time' => 'Listen Time',
            'prase' => 'Prase',
            'collect' => 'Collect',
            'read_times' => 'Read Times',
            'weight' => 'Weight',
            'ctime' => 'Ctime',
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getAudio() {
        return $this->hasOne(Audio::className(), ['id' => 'audio_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUser() {
        return $this->hasOne(User::className(), ['id' => 'user_id']);
    }
}
